module.exports = (sequelize, DataTypes) => {
  const Feedback = sequelize.define('Feedback', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    resourceId: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: {
        model: 'resources',
        key: 'id'
      }
    },
    userId: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: {
        model: 'users',
        key: 'id'
      }
    },
    evaluation: {
      type: DataTypes.ENUM('satisfied', 'unsatisfied'),
      allowNull: false,
      comment: '满意/不满意'
    },
    suggestion: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: '文本意见'
    },
    submitTime: {
      type: DataTypes.DATE,
      defaultValue: DataTypes.NOW
    },
    isTrainingSample: {
      type: DataTypes.BOOLEAN,
      defaultValue: false,
      comment: '是否标记为训练样本'
    }
  }, {
    tableName: 'feedbacks',
    timestamps: true,
    createdAt: 'submitTime',
    updatedAt: false
  });

  Feedback.associate = (models) => {
    // 反馈与用户的多对一关系
    Feedback.belongsTo(models.User, {
      foreignKey: 'userId',
      as: 'user'
    });

    // 反馈与资源的多对一关系
    Feedback.belongsTo(models.Resource, {
      foreignKey: 'resourceId',
      as: 'resource'
    });
  };

  return Feedback;
};